<?php
/**
 * Created by PhpStorm.
 * User: qufan
 * Date: 2016/12/8 0008
 * Time: 22:53
 */

namespace Common\Logic;


use Think\Upload;

class FileLogic
{
    protected $error;

    public function getError(){
        return $this->error;
    }


    public function upload($files, $setting, $driver = 'local', $config = null){
        /* 上传文件 */

        $Upload = new Upload($setting, $driver, $config);
        $info   = $Upload->upload($files);

        if($info){ //文件上传成功，记录文件信息
            foreach ($info as $key => &$value) {
                /* 记录文件信息 */
                $value['path'] = substr($setting['rootPath'], 1).$value['savepath'].$value['savename'];	//在模板里的url路径
            }
            return $info; //文件上传成功
        } else {
            $this->error = $Upload->getError();
            return false;
        }
    }

    /**
     * 检测当前上传的文件是否已经存在
     * @param  array   $file 文件上传数组
     * @return boolean       文件信息， false - 不存在该文件
     */
    public function isFile($file){
        return $file;
    }

}